
package com.probiz.estore.common.model.system;


import com.probiz.estore.common.model.system.base.SystemConfigTbl;

public class SystemConfig extends SystemConfigTbl implements Auditable,	com.probiz.estore.core.model.SystemConfig {

	public final static Short	CONF_DATA_TYPE_STRING		= new Short("1");
	public final static Short	CONF_DATA_TYPE_NUMBER		= new Short("2");
	public final static Short	CONF_DATA_TYPE_BOOLEAN		= new Short("3");

//	public final static Short	CONF_DATA_TYPE_MEDIA		= new Short("5");

//	public final static Short	CONF_INPUT_TYPE_ARRAY		= new Short("4");
//
//	public final static Short	CONF_INPUT_TYPE_CHECKBOX	= new Short("3");
//
//	public final static Short	CONF_INPUT_TYPE_EMAIL		= new Short("6");
//
//	public final static Short	CONF_INPUT_TYPE_FILEPATH	= new Short("104");
//
//	public final static Short	CONF_INPUT_TYPE_IMAGE		= new Short("102");
//
//	public final static Short	CONF_INPUT_TYPE_MAP			= new Short("5");
//
//	public final static Short	CONF_INPUT_TYPE_SELECT		= new Short("2");
//
//	public final static Short	CONF_INPUT_TYPE_TEMPLATE	= new Short("101");
//
//	public final static Short	CONF_INPUT_TYPE_TEXT		= new Short("1");
//
//	public final static Short	CONF_INPUT_TYPE_TEXT_I18N	= new Short("103");
//
//	public final static Short	CONF_MODE_APPLICATION		= new Short("2");
//
//	public final static Short	CONF_MODE_READONLY			= new Short("4");
//
//	public final static Short	CONF_MODE_SYSTEM_HIDDEN		= new Short("1");
//
//	public final static Short	CONF_MODE_USER				= new Short("3");

	private String	oldValue;

	/**
	 * 
	 * Default Empty Constructor for class SystemConfig
	 * 
	 */
	public SystemConfig() {
		super();
	}

	/**
	 * 
	 * Default Key Fields Constructor for class SystemConfig
	 * 
	 */
	public SystemConfig(Integer in_configId) {
		super(in_configId);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.common.model.system.Auditable#getAuditInfo()
	 */
	public AuditInfo getAuditInfo(String methodName) {
		AuditInfo auditInfo = new AuditInfo();
		// Optional, Set entity type/name, default is null. $[...] is a i18n
		// mark.
		auditInfo.setEntityType("$[menu.viewSystemConfigs]");
		// Optional, Set the partial url after ?, so can form the full url which
		// can be clicked by admin. Leading & or ?
		// is not required.
		auditInfo.setSupplementUrl("");
		// Optional, but recommended, Set detailed entity info to be audit,
		// default is the entity.toString().
		StringBuilder sb = new StringBuilder();
		if (oldValue != null) {
			sb.append("{change [").append(getConfigKey()).append("] from [")
					.append(oldValue).append("] to [").append(configValue)
					.append("]}");
		} else {
			sb.append("{change [").append(getConfigKey()).append(
					"] settings only.}");
		}
		auditInfo.setEntityAuditInfo(sb.toString());
		// Optional, Add one methodName - actionName mapping, can add multiple
		// times. default is methodName.
		auditInfo.addActionNameMappings("saveSystemConfig", "Update");
		return auditInfo;
	}

	public boolean getIsValueChanged() {
		return oldValue != null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.common.model.system.base.SystemConfigTbl#setConfigValue(java.lang.String)
	 */
	@Override
	public void setConfigValue(String aValue) {
		if (aValue != null && !aValue.equals(configValue)) {
			oldValue = configValue;
			super.setConfigValue(aValue);
		}
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		return super.equals(obj);
	}
	
}
